<?php

namespace App\Admin\Forms;

use Dcat\Admin\Widgets\Form;

class Setting extends Form
{
    /**
     * Handle the form request.
     *
     * @param array $input
     *
     * @return mixed
     */
    public function handle(array $input)
    {
        // dump($input);
        admin_setting($input);

        // return $this->response()->error('Your error message.');

        return $this->response()->success('请求成功')->refresh();
    }

    /**
     * Build a form here.
     */
    public function form()
    {
        $this->confirm('是否提交表单');
        $this->text('webname', '网站名称')->default(admin_setting('webname', '礼盒商城'));
        $this->url('weburl', '网址地址')->default(admin_setting('weburl', 'http://www.giftedbox.cn/'))->help('正确填写网址', '并且必须以/结尾,否则会导致LOGO无法显示');
        // $this->image('logo', '网址LOGO')->default(admin_setting('weburl','images/19a81c72e263d9badef1b28f7e86bcaa.jpeg'))->accept('jpg,png,gif,jpeg')->maxSize(512)->required()->autoUpload()->help('大小不要超过512K');
        $this->radio('horizontal_menu', '菜单位置')->options([0 => '侧栏', 1 => '顶栏'])->default(admin_setting('horizontal_menu', 0));
        $this->radio('style_type', '网站风格')->options([1 => '旧版', '2' => '大字版'])->default(admin_setting('style_type', 2));
        $this->radio('sidebar_style', '侧栏颜色')->options(['light' => '白色', 'dark' => '黑色', 'primary' => '彩色'])->default(admin_setting('sidebar_style', 'dark'));
        $this->radio('logintheme', '登录页样式')->options(['bigpicture' => '大图', 'simple' => '简单']);
        // $this->image('logobg', '登录页背景图')->accept('jpg,png,gif,jpeg')->maxSize(1024)->autoUpload()->help('大小不要超过512k,仅在登录页为大图模式下生效');
    }

    /**
     * The data of the form.
     *
     * @return array
     */
    public function default()
    {
        return [
            'log' => admin_setting('log', public_path().'/static/img/log.png'),
            'color' => admin_setting('color', 'green'),
            'body_class' => admin_setting('body_class','sidebar-separate'),
            'sidebar_style' => admin_setting('sidebar_style','light'),
            // 'body_class' => admin_setting('body_class', 'sidebar-separate'),
            'logintheme' => admin_setting('logintheme','simple'),
            'logobg' => admin_setting('logobg'),
            'horizontal_menu' => admin_section('horizontal_menu','false'),
            'style_type' => admin_section('style_type',1),
        ];
    }
}
